<template>
<div class="app-container calendar-list-container">
  <div class="filter-container">
    <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="手机号" v-model="listQuery.userMphone"> </el-input>
    <el-select class="filter-item" v-model="listQuery.verfyBusiDic" placeholder="请选择类型">
        <el-option v-for="item in  msgTempOptions" :key="item.templateKey" :label="item.templateName" :value="item.templateKey"> </el-option>
    </el-select>
    <el-select class="filter-item" v-model="listQuery.verfyState" placeholder="请选择状态">
        <el-option v-for="item in  statusOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
    </el-select>
    <el-date-picker class="filter-item" v-model="dateRange" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
    </el-date-picker>
    <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
  </div>
  <el-table :key='tableKey' :data="list" v-loading.body="listLoading" border fit highlight-current-row style="width: 100%">
    <el-table-column align="center" label="序号" min-width="10%"> <template scope="scope">
          <span>{{scope.row.verfyId}}</span>
        </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="手机号"> <template scope="scope">
        <span>{{scope.row.userMphone}}</span>
      </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="验证码"> <template scope="scope">
            <span>{{scope.row.verfyStr}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="业务类型"> <template scope="scope">
            <span>{{scope.row.templateName}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="创建时间"> <template scope="scope">
            <span>{{scope.row.createTime}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="状态"> <template scope="scope">
            <span>{{scope.row.verfyStateName}}</span>
          </template> </el-table-column>
    <el-table-column min-width="10%" align="center" label="验证时间"> <template scope="scope">
            <span>{{scope.row.verfyDate}}</span>
          </template> </el-table-column>
  </el-table>
  <div v-show="!listLoading" class="pagination-container">
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.pageNo" :page-sizes="[10,20,30, 50]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
  </div>
</div>
</template>

<script>
import {
  page
} from 'api/msg/verifyCode/index';
import {
  queryAll
} from 'api/msg/template/index';
import { mapGetters } from 'vuex';
export default {
  name: 'verifyCode',
  data() {
    return {
      list: null,
      total: null,
      listLoading: true,
      dateRange : null,
      listQuery: {
        pageNo: 1,
        pageSize: 20,
        startTime : undefined,
        endTime : undefined,
        userMphone: undefined,
        verfyState: undefined,
        verfyBusiDic : undefined
      },
      msgTempOptions: undefined,
      statusOptions:[
        {value: '0',label: '待验证'},
        {value: '1',label: '已验证'}
      ],
      tableKey: 0
    }
  },
  created() {
    this.getList();
    this.getMsgTemplist();
  },
  computed: {
    ...mapGetters([
      'elements'
    ])
  },
  methods: {
    getList() {
      this.listLoading = true;
      page(this.listQuery)
        .then(response => {
          this.list = response.data.rows;
          this.total = response.data.total;
          this.listLoading = false;
        })
    },
    getMsgTemplist() {
      queryAll()
        .then(response => {
          this.msgTempOptions = response.data;
        })
    },
    handleFilter() {
      if(this.dateRange != null){
        this.listQuery.startTime = this.dateRange[0];
        this.listQuery.endTime = this.dateRange[1];
      }
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNo = val;
      this.getList();
    }
  }
}
</script>